package com.dm.cloud.auth.controller.defalut;

import com.dm.cloud.auth.common.mode.AuthUserPermissionSaveModel;
import com.dm.cloud.core.mode.ResultModel;
import com.dm.cloud.oauthlib.service.anon.HasLogin;
import com.dm.cloud.tkmybatis.service.BaseEntityService;
import com.dm.cloud.tkmybatis.service.EntityBaseController;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import com.dm.cloud.auth.common.po.AuthPermission;
import com.dm.cloud.auth.common.dto.AuthPermissionDTO;
import com.dm.cloud.auth.common.request.AuthPermissionSearchRequest;
import com.dm.cloud.auth.service.AuthPermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
   * @author hcx
   * @type AuthPermissionController.java
   * @desc 权限表 AuthPermission controller
   */
@RestController
@RequestMapping("/apis/v1/authPermission")
@Tag(name =  "权限表  AuthPermissioncontroller")
@HasLogin
public class AuthPermissionController extends EntityBaseController<AuthPermissionSearchRequest, AuthPermission, AuthPermissionDTO> {


    @Autowired
    private AuthPermissionService authPermissionService;
    @Override
    public AuthPermission getEntity() {
        return new AuthPermission();
    }

    @Override
    public AuthPermissionDTO getDTO() {
        return new AuthPermissionDTO();
    }
    @Override
    public BaseEntityService<AuthPermissionSearchRequest, AuthPermission> getService() {
        return authPermissionService;
    }

    @PostMapping("rolePermission")
    @Operation(summary = "添加角色权限")
    public ResultModel<Integer> rolePermission(
            @RequestBody AuthUserPermissionSaveModel saveModel){
        return ResultModel.success(authPermissionService.saveRolePermission(saveModel));
    }

    @GetMapping("rolePermission")
    @Operation(summary = "查询角色权限")
    public ResultModel<List<String>> getRolePermissions(
            @Parameter(description = "角色ID",in = ParameterIn.QUERY,required = true) String roleId){
        return ResultModel.success(authPermissionService.getRolePermissions(roleId));
    }

}
